const http = require('http')
const url = require('url')
const qs = require('querystring');
const server = http.createServer((req, res) => {
  console.log(req.url)
  console.log(req.method)
  const { pathname } = url.parse(req.url)
  if(pathname === '/login') {
    if (req.method === 'POST') {
      // 拿到body中的数据
      req.setEncoding('utf-8')
      req.on('data', (data) => {
        console.log(data)
        const {username, password } = JSON.parse(data)
        console.log(username, password)
      })
      res.end('server')
    }
  }
})
server.listen(8091, () => {
  console.log('server')
})